package com.sc.thread.threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by Shen Chao on 2018-06-14-014.
 * ScheduledThreadPool可以定时的或延时的执行任务。
 */
public class ScheduledThreadPoolTest {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService
                = Executors.newScheduledThreadPool(1);
        //3秒后执行
        scheduledExecutorService.schedule(
                () -> System.out.println("执行"), 3000, TimeUnit.MILLISECONDS);
        //3秒后执行，然后每两秒执行一次
        scheduledExecutorService.scheduleAtFixedRate(
                () -> System.out.println("执行"), 3, 2, TimeUnit.SECONDS);
    }
}
